<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File: function.showValue.php
 * Type: function
 * Name: showValue
 * Purpose: output the value of a array by key
 * 
 * -------------------------------------------------------------
 */
function smarty_function_showValue($aParameter, &$smarty)
{
	$scNotSetKey = "Please set selected key!";
    $sPreFormat  = "<font style='color:#FF0000;font-weight:bold;font-size:15px;vertical-align:middle;'>";
    $sLastFormat = "</font>";

	$sOutput   = "";
	$sFetchKey = "";
	$sFormID   = "";
	$aOptions  = array();
	$sDebug    = true;
		
	//fetch all data from $aParameter
	foreach($aParameter as $_key => $_val)
	{
		switch($_key) 
		{
		    case 'key':
		        $sFetchKey = (string)$_val;
		        break;
		    
		    case 'aMsg':
		        $aOptions = (array)$_val;
		        break;
		    
		    case 'formid':
		        $sFormID = $_val;
		        break;
		    
		    case 'debug':
		        $sDebug = $_val;
		        
		    default:
		    	break;
		}
	}

	//deal the data
	if(empty($sFetchKey)) 
	{
	    if (true == $sDebug)
    	{
    	    $sOutput = $sPreFormat.$scNotSetKey.$sLastFormat;
        }
	}
	if(array_key_exists($sFetchKey, $aOptions))
	{
		$sOutput = $aOptions[$sFetchKey];
	}
	else
	{
	    if (true == $sDebug)
	    {
	        if (isset($aOptions["gFormid"]))
	        {
	            $sOutput = $sPreFormat .$aOptions["gFormid"];
	            $sOutput.= "." .$sFetchKey .$sLastFormat;
	        }
	    }
	}

	return 	$sOutput;
	
}
?>